local fengxi = fk.CreateSkill{
    name = "ym2__fengxi",
}
Fk:loadTranslationTable{
    ["ym2__fengxi"] = "锋袭",
    [":ym2__fengxi"] = "出牌阶段，你可以视为使用一张【杀】并令你与目标角色的一个技能本回合失效，若不含此技能则你与其计算与对方的距离+1，直到你下回合结束。",
    ["#ym2__fengxi"] = "锋袭：视为使用一张【杀】，并令你与目标角色的一个技能本回合失效",
    ["#ym2__fengxi-skill"] = "锋袭：令 %dest 的一个技能本回合失效！",
}

fengxi:addEffect("viewas", {
    anim_type = "offensive",
    prompt = "#ym2__fengxi",
    card_filter = Util.FalseFunc,
    view_as = function(self, player, cards)
        if #cards ~= 0 then return end
        local card = Fk:cloneCard("slash")
        card.skill = Fk.skills["ym2z_machao__slash_skill"]
        card.skillName = fengxi.name
        return card
    end,
    before_use = function (self, player, use)
        local room = player.room

        local choice

        if #table.filter(player:getSkillNameList(), function (s)
                return player:hasSkill(s)
        end) > 0 then
            choice = room:askToCustomDialog(player, {
                skill_name = fengxi.name,
                qml_path = "packages/utility/qml/ChooseSkillBox.qml",
                extra_data = { table.filter(player:getSkillNameList(), function (s)
                    return player:hasSkill(s)
                end), 1, 1, "#ym2__fengxi-skill::"..player.id, {} },
            })
            if choice == "" then
                choice = table.random(table.filter(player:getSkillNameList(), function (s)
                    return player:hasSkill(s)
                end))
            else
                choice = choice[1]
            end
            room:invalidateSkill(player, choice, "-turn", fengxi.name)
        end

        for _, tp in ipairs(use.tos) do
            if #table.filter(tp:getSkillNameList(), function (s)
                return tp:hasSkill(s)
            end) > 0 then
                local choice2 = room:askToCustomDialog(player, {
                    skill_name = fengxi.name,
                    qml_path = "packages/utility/qml/ChooseSkillBox.qml",
                    extra_data = { table.filter(tp:getSkillNameList(), function (s)
                        return tp:hasSkill(s)
                    end), 1, 1, "#ym2__fengxi-skill::"..tp.id, {} },
                })
                if choice2 == "" then
                    choice2 = table.random(table.filter(tp:getSkillNameList(), function (s)
                        return tp:hasSkill(s)
                    end))
                else
                    choice2 = choice2[1]
                end
                room:invalidateSkill(tp, choice2, "-turn", fengxi.name)
            end
        end

        if choice ~= fengxi.name then
            local mark = player:getTableMark(fengxi.name)
            mark.this = mark.this or {}
            mark.next = mark.next or {}
            for _, tp in ipairs(use.tos) do
                table.insert(mark.next, tp.id)
            end
            room:setPlayerMark(player, fengxi.name, mark)
        end
    end,
    enabled_at_play = function(self, player)
        return player.phase == Player.Play
    end,
})
fengxi:addEffect(fk.TurnEnd, {
    late_refresh = true,
    can_refresh = function (self, event, target, player, data)
        if target == player then
            local mark = player:getTableMark(fengxi.name)
            mark.this = mark.this or {}
            mark.next = mark.next or {}
            return #mark.this > 0 or #mark.next > 0
        end
    end,
    on_refresh = function (self, event, target, player, data)
        local room = player.room
        local mark = player:getTableMark(fengxi.name)
        mark.next = mark.next or {}
        mark.this = table.simpleClone(mark.next)
        mark.next = {}
        room:setPlayerMark(player, fengxi.name, mark)
    end,
})
fengxi:addEffect("distance", {
    correct_func = function(self, from, to)
        if from:getMark(fengxi.name) ~= 0 then
            local mark = from:getTableMark(fengxi.name)
            mark.this = mark.this or {}
            mark.next = mark.next or {}
            return #table.filter(mark.this, function (cpID)
                return cpID == to.id
            end) + #table.filter(mark.next, function (cpID)
                return cpID == to.id
            end)
        end
        if to:getMark(fengxi.name) ~= 0 then
            local mark = to:getTableMark(fengxi.name)
            mark.this = mark.this or {}
            mark.next = mark.next or {}
            return #table.filter(mark.this, function (cpID)
                return cpID == from.id
            end) + #table.filter(mark.next, function (cpID)
                return cpID == from.id
            end)
        end
    end,
})
fengxi:addAcquireEffect(function (self, player, is_start)
    player.room:setPlayerMark(player, fengxi.name, {this = {}, next = {}})
end)

return fengxi